package com.morn.weibo;

import java.sql.SQLException;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;

import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.dao.Dao;
import com.morn.weibo.db.FanfouOpenHelper;
import com.morn.weibo.http.Fanfou;
import com.morn.weibo.types.UserAccount;

public class LogoActivity extends OrmLiteBaseActivity<FanfouOpenHelper> {

	private Fanfou fanfou;
	private Dao<UserAccount, Integer> userAccountdao;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		fanfou = WeiboApplication.getFanfou();
		List<UserAccount> userAccountList = null;
		UserAccount userAccount = null;
		try {
			userAccountdao = getHelper().getUserAccountDao();
			userAccountList = userAccountdao.queryForAll();
			if (userAccountList != null && userAccountList.size() > 0) {
				userAccount = userAccountList.get(0);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		if (userAccount != null) {
			fanfou.setCredentials(userAccount);
			Intent intentMain = new Intent(this, MainActivity.class);
			this.startActivity(intentMain);
			this.finish();
		} else {
			Intent intentLogin = new Intent(this, LoginActivity.class);
			this.startActivity(intentLogin);
			this.finish();
		}
	}
}
